﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public class HYCalSQLData
	{
		public static List<HYRiserRange> GetRiserRange()
		{
			List<HYRiserRange> list = new List<HYRiserRange>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("DrainRiserChoose").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				HYRiserRange item = new HYRiserRange(Convert.ToInt32(dataRow["DN"].ToString()), Convert.ToDouble(dataRow["VentilQ"].ToString()), Convert.ToDouble(dataRow["NoVentilQ"].ToString()));
				list.Add(item);
			}
			return list;
		}

		public static List<HYDrainGradFullness> GetGradFullness(int nType)
		{
			List<HYDrainGradFullness> list = new List<HYDrainGradFullness>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("DrainGradAndFullness").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				HYDrainGradFullness hydrainGradFullness = new HYDrainGradFullness();
				int num = Convert.ToInt32(dataRow["Type"].ToString());
				if (nType <= 0 || nType == num)
				{
					hydrainGradFullness.nType = Convert.ToInt32(dataRow["Type"].ToString());
					hydrainGradFullness.nDN = Convert.ToInt32(dataRow["DN"].ToString());
					hydrainGradFullness.dUseGrad = Convert.ToDouble(dataRow["UserGrad"].ToString());
					hydrainGradFullness.dMinGrad = Convert.ToDouble(dataRow["MinGrad"].ToString());
					hydrainGradFullness.dFullness = Convert.ToDouble(dataRow["Fullness"].ToString());
					hydrainGradFullness.szDis = dataRow["Des"].ToString();
					list.Add(hydrainGradFullness);
				}
			}
			return list;
		}

		public static Dictionary<double, double> GetSupplyACoefficient()
		{
			Dictionary<double, double> dictionary = new Dictionary<double, double>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("SupplyACoefficient").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				double key = Convert.ToDouble(dataRow["Uo"].ToString());
				double value = Convert.ToDouble(dataRow["a"].ToString());
				dictionary.Add(key, value);
			}
			return dictionary;
		}

		public static Dictionary<int, double> GetSupplyEconomicalFlow()
		{
			Dictionary<int, double> dictionary = new Dictionary<int, double>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("SupplyEconomicalFlow").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				int key = Convert.ToInt32(dataRow["DN"].ToString());
				double value = Convert.ToDouble(dataRow["Flow"].ToString());
				dictionary.Add(key, value);
			}
			return dictionary;
		}

		public static Dictionary<int, string> GetSupplyBuildingCoefficientName()
		{
			Dictionary<int, string> dictionary = new Dictionary<int, string>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("SupplyBuildingCoefficient").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				int key = Convert.ToInt32(dataRow["Id"].ToString());
				string value = dataRow["Name"].ToString();
				dictionary.Add(key, value);
			}
			return dictionary;
		}

		public static Dictionary<string, double> GetSupplyBuildingNameCoefficient()
		{
			Dictionary<string, double> dictionary = new Dictionary<string, double>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("SupplyBuildingCoefficient").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				string key = dataRow["Name"].ToString();
				double value = Convert.ToDouble(dataRow["Arfa"].ToString());
				dictionary.Add(key, value);
			}
			return dictionary;
		}

		public static Dictionary<int, double> GetSupplyBuildingCoefficient()
		{
			Dictionary<int, double> dictionary = new Dictionary<int, double>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("SupplyBuildingCoefficient").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				int key = Convert.ToInt32(dataRow["Id"].ToString());
				double value = Convert.ToDouble(dataRow["Arfa"].ToString());
				dictionary.Add(key, value);
			}
			return dictionary;
		}

		public static List<SupplyFamilyCofi> GetSupplyFamilyCoefficient()
		{
			List<SupplyFamilyCofi> list = new List<SupplyFamilyCofi>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("SupplyFamilyCoefficient").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				list.Add(new SupplyFamilyCofi
				{
					id = Convert.ToInt32(dataRow["Id"].ToString()),
					name = dataRow["Name"].ToString(),
					userwater = Convert.ToDouble(dataRow["UserWater"].ToString()),
					changetime = Convert.ToDouble(dataRow["ChangeTime"].ToString()),
					usertime = Convert.ToDouble(dataRow["UserTime"].ToString())
				});
			}
			return list;
		}

		public static List<string> GetBuildingTypes()
		{
			List<string> list = new List<string>();
			foreach (object obj in new HYMEPDatasourceReader().GetPumpDataTable("SprayBuilding").Rows)
			{
				DataRow dataRow = (DataRow)obj;
				list.Add(dataRow["BuildingType"].ToString());
			}
			return list;
		}

		public static List<UsedWaterCalculate> GetUsedWaterTypes()
		{
			List<UsedWaterCalculate> list = new List<UsedWaterCalculate>();
			try
			{
				DataTable pumpDataTable = new HYMEPDatasourceReader().GetPumpDataTable("UsedWaterType");
				if (pumpDataTable != null)
				{
					foreach (object obj in pumpDataTable.Rows)
					{
						DataRow dataRow = (DataRow)obj;
						list.Add(new UsedWaterCalculate((WaterCalculateType)Convert.ToInt32(dataRow["BuildingType"].ToString()), dataRow["Name"].ToString())
						{
							maxUsedRange = dataRow["MaxValueRange"].ToString(),
							maxUsedProposal = Convert.ToDouble(dataRow["MaxValueProposal"].ToString()),
							usedTime = dataRow["UsedTime"].ToString(),
							usedTimeProposal = Convert.ToDouble(dataRow["UsedTimeProposal"].ToString()),
							coefficientRange = dataRow["CofficientRange"].ToString(),
							coefficientProposal = Convert.ToDouble(dataRow["CofficientProposal"].ToString()),
							unit = dataRow["Unit"].ToString(),
							usedCount = 1.0
						});
					}
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.Message);
			}
			return list;
		}

		public static List<HotUsedWaterCal> GetHotUsedWaterDayData()
		{
			List<HotUsedWaterCal> list = new List<HotUsedWaterCal>();
			try
			{
				DataTable pumpDataTable = new HYMEPDatasourceReader().GetPumpDataTable("HotUsedWaterDayCal");
				if (pumpDataTable != null)
				{
					foreach (object obj in pumpDataTable.Rows)
					{
						DataRow dataRow = (DataRow)obj;
						list.Add(new HotUsedWaterCal((WaterCalculateType)Convert.ToInt32(dataRow["CalculateType"].ToString()), dataRow["Name"].ToString())
						{
							maxUsedRange = dataRow["maxUsedRange"].ToString(),
							maxUsedProposal = Convert.ToDouble(dataRow["maxUsedProposal"].ToString()),
							usedTimeRange = dataRow["usedTimeRange"].ToString(),
							usedTimeProposal = Convert.ToDouble(dataRow["usedTimeProposal"].ToString()),
							unit = dataRow["unit"].ToString(),
							coefficientProposal = Convert.ToDouble(dataRow["Per"].ToString()),
							usedCount = 1.0
						});
					}
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.Message);
			}
			return list;
		}

		public static List<HotUsedWaterCal> GetHotUsedWaterHourData()
		{
			List<HotUsedWaterCal> list = new List<HotUsedWaterCal>();
			try
			{
				DataTable pumpDataTable = new HYMEPDatasourceReader().GetPumpDataTable("HotUsedWaterHourCal");
				if (pumpDataTable != null)
				{
					foreach (object obj in pumpDataTable.Rows)
					{
						DataRow dataRow = (DataRow)obj;
						list.Add(new HotUsedWaterCal((WaterCalculateType)Convert.ToInt32(dataRow["CalculateType"].ToString()), dataRow["Name"].ToString())
						{
							maxUsedRange = dataRow["maxUsedRange"].ToString(),
							maxUsedProposal = Convert.ToDouble(dataRow["maxUsedProposal"].ToString()),
							oneUsedRange = dataRow["oneUsedRange"].ToString(),
							usedTempProposal = Convert.ToDouble(dataRow["usedTempProposal"].ToString()),
							usedTempRange = dataRow["usedTempRange"].ToString(),
							coefficientProposal = Convert.ToDouble(dataRow["Per"].ToString()),
							usedCount = 1.0
						});
					}
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.Message);
			}
			return list;
		}

		public static List<EquivalentLength> GetEquivalentValues()
		{
			List<EquivalentLength> list = new List<EquivalentLength>();
			try
			{
				DataTable pumpDataTable = new HYMEPDatasourceReader().GetPumpDataTable("EquivalentLength");
				if (pumpDataTable != null)
				{
					foreach (object obj in pumpDataTable.Rows)
					{
						DataRow dataRow = (DataRow)obj;
						list.Add(new EquivalentLength
						{
							ID = Convert.ToInt32(dataRow["Id"]),
							Name = dataRow["Name"].ToString(),
							DN = Convert.ToInt32(dataRow["DN"]),
							EquivalentValue = Convert.ToDouble(dataRow["Equivalent"])
						});
					}
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.Message);
			}
			return list;
		}

		public static List<SupplyTerminal> GetSupplyTerminal()
		{
			List<SupplyTerminal> list = new List<SupplyTerminal>();
			try
			{
				DataTable tableSchema = new SQLiteDataBaseHelper(Path.Combine(Product.DataLocation, "HYBIMSPACE.db3")).GetTableSchema("SanitarySupplyTerminal");
				if (tableSchema != null && tableSchema.Rows.Count > 0)
				{
					foreach (object obj in tableSchema.Rows)
					{
						DataRow dataRow = (DataRow)obj;
						list.Add(new SupplyTerminal
						{
							Id = int.Parse(dataRow["Id"].ToString()),
							Name = dataRow["Name"].ToString(),
							KeyWord = dataRow["Keyword"].ToString(),
							Image = Path.Combine(Product.FamilyImageLocation, "SanitarySupplyTerminal", dataRow["Image"].ToString())
						});
					}
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.Message);
			}
			return list;
		}

		public static Dictionary<string, int> GetSupplyBathroomPer(string szBuildType)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			try
			{
				DataTable pumpDataTable = new HYMEPDatasourceReader().GetPumpDataTable("SupplyBathroomPer");
				if (pumpDataTable != null && pumpDataTable.Rows.Count > 0)
				{
					foreach (object obj in pumpDataTable.Rows)
					{
						DataRow dataRow = (DataRow)obj;
						dictionary.Add(dataRow["Name"].ToString(), Convert.ToInt32(dataRow[szBuildType].ToString()));
					}
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.Message);
			}
			return dictionary;
		}
	}
}
